package cj.hrm.dao;

import cj.hrm.dao.provider.CheckworkDynaSqlProvider;
import cj.hrm.entity.Checkwork;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;

import java.util.List;
import java.util.Map;

import static cj.hrm.util.common.HrmConstants.*;


public interface CheckworkDao {
	//查询
	@SelectProvider(type= CheckworkDynaSqlProvider.class,method="selectWhitParam")
	@Results({
		@Result(id=true,column="id",property="id"),
		@Result(column="DEPT_ID",property="dept",
		one=@One(select="cj.hrm.dao.DeptDao.selectById",
		fetchType=FetchType.EAGER)),
		@Result(column="EMP_ID",property="employee",
		one=@One(select="cj.hrm.dao.EmployeeDao.selectById",
	fetchType=FetchType.EAGER)),
		@Result(column="JOB_ID",property="job",
		one=@One(select="cj.hrm.dao.JobDao.selectById",
	fetchType=FetchType.EAGER))
	})
	List<Checkwork> selectByPage(Map<String, Object> params);
	
	
	
	@Select("select * from "+CHECKWORKTABLE+"  where WORKINGDAYS like binary CONCAT('%',#{content},'%')"
			+ "or DAYSLEAVE like binary CONCAT('%',#{content},'%')"
			+ "or CREATEDATE like binary CONCAT('%',#{content},'%')"
			+ "or DEPT_ID =(select id from "+DEPTTABLE+" where name like binary CONCAT('%',#{content},'%'))"
			+ "or JOB_ID =(select id from "+JOBTABLE+" where name like binary CONCAT('%',#{content},'%'))"
			+ "or EMP_ID =(select id from "+EMPLOYEETABLE+" where name like binary CONCAT('%',#{content},'%'))"
			+ "or DAYSOUT like binary CONCAT('%',#{content},'%')")
	@Results({
		@Result(id=true,column="id",property="id"),
		@Result(column="DEPT_ID",property="dept",
		one=@One(select="cj.hrm.dao.DeptDao.selectById",
		fetchType=FetchType.EAGER)),
		@Result(column="EMP_ID",property="employee",
		one=@One(select="cj.hrm.dao.EmployeeDao.selectById",
	fetchType=FetchType.EAGER)),
		@Result(column="JOB_ID",property="job",
		one=@One(select="cj.hrm.dao.JobDao.selectById",
	fetchType=FetchType.EAGER))
	})
	List<Checkwork> get_LikeList(String content);
	
	@Select("select count(*) from "+CHECKWORKTABLE+"  where WORKINGDAYS like binary CONCAT('%',#{content},'%')"
			+ "or DAYSLEAVE like binary CONCAT('%',#{content},'%')"
			+ "or CREATEDATE like binary CONCAT('%',#{content},'%')"
			+ "or DEPT_ID =(select id from "+DEPTTABLE+" where name like binary CONCAT('%',#{content},'%'))"
			+ "or JOB_ID =(select id from "+JOBTABLE+" where name like binary CONCAT('%',#{content},'%'))"
			+ "or EMP_ID =(select id from "+EMPLOYEETABLE+" where name like binary CONCAT('%',#{content},'%'))"
			+ "or DAYSOUT like binary CONCAT('%',#{content},'%')")
	public Integer countCheckwork(String content);
	
	
	@Select("select * from "+CHECKWORKTABLE+" where emp_id = #{id}")
	Checkwork getEmp_id(Integer id);
	
	
	@SelectProvider(type=CheckworkDynaSqlProvider.class,method="insertCheckwork")
	void insert_CheckWork(Checkwork checkwork);
	
	@Select("select * from "+CHECKWORKTABLE+" where id = #{id}")
	@Results({
		@Result(id=true,column="id",property="id"),
		@Result(column="DEPT_ID",property="dept",
		one=@One(select="cj.hrm.dao.DeptDao.selectById",
		fetchType=FetchType.EAGER)),
		@Result(column="EMP_ID",property="employee",
		one=@One(select="cj.hrm.dao.EmployeeDao.selectById",
	fetchType=FetchType.EAGER)),
		@Result(column="JOB_ID",property="job",
		one=@One(select="cj.hrm.dao.JobDao.selectById",
	fetchType=FetchType.EAGER))
	})
	Checkwork selectById(Integer id);

	@SelectProvider(type=CheckworkDynaSqlProvider.class,method="updateCheckwork")
	void update_Checkwork(Checkwork checkwork);
	// 根据id删除部门
	@Delete(" delete from "+CHECKWORKTABLE+" where id = #{id} ")
	void deleteCheckworkById(Integer id);
	
	
	// 根据参数查询员工总数
    /**
     * Mybatis @SelectProvider 用自定义的provider类构造SQL语句
     * @param params
     * @return
     */
	@SelectProvider(type=CheckworkDynaSqlProvider.class,method="count")
	public Integer count(Map<String, Object> params);

}
